<!-- 案场信息编辑弹窗 -->
<template>
  <div class="basicInformation_modal">
    <!-- 编辑弹窗 -->
    <dt-modal-edit
      ref="edit"
      :title="title"
      :label-width="130"
      okText="确定"
      :width="80"
      @ok="saveTableDatail"></dt-modal-edit>
  </div>
</template>
<script>
  import buildingApi from '@/biz/buildingManagement/basicInfo'
  import editMgr from '../opt/editOpt'
  export default {
    data() {
      return {
        info: {
          expectedOpenTime: '',
          enterDate: '',
          cooperationMode: '',
          agencyRateMin: '',
          agencyRateMax: '',
          address: '',
          detailedAddress: '',
          securityFundMoney: ''
          // provinceCode: '',
          // cityCode: '',
          // areaCode: '',
          // streetCode: '',
        },
        flag: '',
        statusAttrSort: [],
        title: '编辑案场信息'
      }
    },
    methods: {
      show(data) {
        console.log(data, 'show====data')
        this.flag = data.basicInformationFlag
        this.statusAttrSort = data.statusAttrSort
        data.provinceCode = data.provinceId ? String(data.provinceId) : ''
        data.provinceName = data.province
        data.cityCode = data.cityId ? String(data.cityId) : ''
        data.cityName = data.city
        data.areaCode = data.areaId ? String(data.areaId) : ''
        data.areaName = data.area
        data.streetCode = data.plateId ? String(data.plateId) : ''
        data.streetName = data.plate
        data.isSecurityFund = data.isSecurityFund ? '1' : '0'
        data.securityFundMoney =
          data.securityFundMoney || data.securityFundMoney == 0 ? String(data.securityFundMoney) : ''
        data.agencyRateMin = data.agencyRateMin || data.agencyRateMin == 0 ? String(data.agencyRateMin) : ''
        data.agencyRateMax = data.agencyRateMax || data.agencyRateMax == 0 ? String(data.agencyRateMax) : ''
        data.expectedOpenTime = data.expectedOpenTime ? String(data.expectedOpenTime) : ''
        Object.assign(this.info, data)
        this.$refs.edit.show(editMgr.options(this), this.info)
      },
      hide() {
        console.log(this.info, 'hide====info')
        this.$refs.edit.hide()
      },
      //字段修改保存
      saveTableDatail() {
        console.log(this.info, 'info')
        this.info.provinceId = this.info.provinceCode
        this.info.province = this.info.provinceName
        this.info.cityId = this.info.cityCode
        this.info.city = this.info.cityName
        this.info.areaId = this.info.areaCode
        this.info.area = this.info.areaName
        this.info.plateId = this.info.streetCode || ''
        this.info.plate = this.info.streetName
        this.info.securityFundMoney = this.info.securityFundMoney ? this.info.securityFundMoney : null
        let params = { ...this.info }
        params.isSecurityFund = this.info.isSecurityFund == '1' ? true : false
        buildingApi.housesEditBaseInfo(params).then((res) => {
          this.$Message.success('修改成功')
          if (this.info.cooperationMode == 4 || this.info.cooperationMode == 5) {
            this.$Message.info({
              content: '包销项目请注意完成底价上传',
              duration: 2
            })
          }
          this.$emit('onChangeData')
          this.hide()
        })
      }
    },
    mounted() {}
  }
</script>
<style lang="scss" scoped></style>
